package com.zjc.mymq.broker.utils;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author zjc
 * @date Created in 15:59 2024/6/4
 */
public class SpinLock implements PutMessageLock, AckMessageLock {

	AtomicInteger atomicInteger = new AtomicInteger(0);

	@Override
	public void lock() {
		do {
			int result = atomicInteger.getAndIncrement();
			if (result == 1) {
				return;
			}
		} while (true);
	}

	@Override
	public void unlock() {
		atomicInteger.decrementAndGet();
	}
}
